/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-08-13 15:54:35
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-08-14 10:44:04
 */

const data = require.context("../components", true, /demo./);
const filnameHandle = (key: string) => {
  const name = key.split("/");
  const _keyarr = key.split(".");
  return `/${_keyarr[2]}/${name[1].toLowerCase()}`;
};
function autoCreateRoutes(files: any) {
  return files.keys().reduce((init: any[], key: string) => {
    init.push({
      path: filnameHandle(key),
      component: files(key).default,
    });
    return init;
  }, []);
}

export default autoCreateRoutes(data);
